package com.example.user.chain;

/**
 * Author:汪彬彬
 * date:2024/11/20 16:08
 */

import com.example.user.entity.po.Order;
import com.example.user.handler.OrderHandler;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * Spring+职责链模式+多级校验
 * 通过设计模式实现多级校验与业务分离
 */
@Component
public class OrderHandlerChain {

    private  final List<OrderHandler> handlers;

   //注入所有实现OrderHandler 接口得组件
    public OrderHandlerChain(List<OrderHandler> handlers) {
        this.handlers = handlers;
    }
    public boolean process(Order order){
       if(handlers.stream().anyMatch(x->x.handle(order)==false)){
           return  false;
       } else {
           return  true;
       }
    }



}
